//
//  SXTopicMainLeftViewController.m
//  ShiXun
//
//  Created by lanou on 15/10/27.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SXTopicMainLeftViewController.h"
#import "SXTopicMainLeftTableViewCell.h"
#import "UIView+UIView.h"



@interface SXTopicMainLeftViewController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *leftTableView;
@property (nonatomic, strong) NSArray *listarray;
@property (nonatomic, strong) NSIndexPath *selectedIdexPath;

@end

@implementation SXTopicMainLeftViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _selectedIdexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    
    _listarray = @[@"热门",@"特色",@"娱乐",@"生活",@"交友",@"体育",@"影视",@"科技",@"财经",@"汽车",@"杂谈"];
    
    _leftTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, kScreenWidth / 5, kScreenHeight - 113) style:(UITableViewStylePlain)];
    _leftTableView.dataSource = self;
    _leftTableView.delegate = self;
    _leftTableView.rowHeight = 50;
    _leftTableView.tableFooterView =  [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth / 5, 0.5)];
    [_leftTableView registerClass:[SXTopicMainLeftTableViewCell class] forCellReuseIdentifier:@"leftTableView"];
    
    [self.view addSubview:_leftTableView];
}
// 选中改变颜色
- (void)setSelectedIdexPath:(NSIndexPath *)selectedIdexPath
{
    SXTopicMainLeftTableViewCell *deselectCell = (SXTopicMainLeftTableViewCell *)[self.leftTableView cellForRowAtIndexPath:_selectedIdexPath];
    if (deselectCell) {
        deselectCell.contentView.backgroundColor = [UIColor colorWithRed:0.8608 green:0.8608 blue:0.8608 alpha:1.0];
        deselectCell.lisetLabel.textColor = [UIColor blackColor];
    }
    
    _selectedIdexPath = selectedIdexPath;
    SXTopicMainLeftTableViewCell *selectcell = (SXTopicMainLeftTableViewCell *)[self.leftTableView cellForRowAtIndexPath:_selectedIdexPath];
    selectcell.contentView.backgroundColor = [UIColor whiteColor];
    selectcell.lisetLabel.textColor = [UIColor redColor];
}
// 点击当前 cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.selectedIdexPath = indexPath;
    self.rightVC.subscript = indexPath.row;
    self.rightVC.titleItem = _listarray[indexPath.row];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 11;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SXTopicMainLeftTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"leftTableView" forIndexPath:indexPath];

    if (indexPath.row == _selectedIdexPath.row) {
        cell.selected = YES;
    }
    cell.lisetLabel.text = _listarray[indexPath.row];
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
